﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ReportDoanhThu.aspx.cs" Inherits="CMS.ReportDoanhThu" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Charting" Assembly="Telerik.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <div style="font-size: 26px; font-weight: bold; text-align: center;">BÁO CÁO DOANH THU</div>
    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
        <table>
            <tr>
                <td>Từ ngày :
        <telerik:RadDatePicker ID="txtFromDate" runat="server" Skin="Default" DateInput-DateFormat="MM/dd/yyyy HH:mm:ss"
            DateInput-DisplayDateFormat="dd/MM/yyyy HH:mm:ss">
        </telerik:RadDatePicker>
                </td>
                <td>Đến ngày :
        <telerik:RadDatePicker ID="txtToDate" runat="server" Skin="Default" DateInput-DateFormat="MM/dd/yyyy HH:mm:ss"
            DateInput-DisplayDateFormat="dd/MM/yyyy HH:mm:ss">
        </telerik:RadDatePicker>
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Xem" OnClick="Button1_Click" /></td>
            </tr>
        </table>
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="True" PageSize="20" GridLines="None" Width="100%" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField HeaderText="Ngày" DataField="DateWin"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng tài khoản" DataField="CountAcc" DataFormatString="{0:n0}"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng giao dịch" DataField="CountBet" DataFormatString="{0:n0}"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng luồng tiền" DataField="SUMBetMoney" DataFormatString="{0:n0}"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng tiền chi" DataField="SUMWinMoney" DataFormatString="{0:n0}"></asp:BoundField>
                <asp:BoundField HeaderText="Lợi nhuận" DataField="SUMProfit" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng TK mới" DataField="CountAccNew" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
                <asp:BoundField HeaderText="Số giao dịch TK mới" DataField="CountBetNew" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
                <asp:BoundField HeaderText="Tổng tiền giao dịch" DataField="SUMBetMoneyNew" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
                <asp:BoundField HeaderText="Luồng tiền TK mới" DataField="SUMWinMoneyNew" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
                <asp:BoundField HeaderText="Lợi nhuận TK mới" DataField="SUMProfitNew" DataFormatString="{0:n0}" NullDisplayText="0"></asp:BoundField>
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        </asp:GridView>
        <br />
        <br />
        <div>
            <br />
            <div style="text-align: center;">
                <div id="chart_loinhuan"></div>
                <div id="chart_giaodich"></div>


                <button type="button" id="hideTT">Ẩn Tổng Tiền</button>
                <script type="text/javascript" src="https://www.google.com/jsapi"></script>
                <script type="text/javascript">
                    google.load("visualization", "1", { packages: ["corechart"] });
                    function format(data) {
                        var r1 = new Array();
                        var r2 = new Array();
                        r2.push('DAY');
                        r2.push('Giao Dịch');
                        r2.push('Tài khoản');
                        r1.push(r2);

                        var r1sum = new Array();
                        var r2sum = new Array();
                        r2sum.push('DAY');
                        r2sum.push('Tổng Tiền (VCoin)');
                        r2sum.push('Lợi nhuận (VCoin)');
                        r1sum.push(r2sum);

                        for (var i = data.length - 1; i >= 0; i--) {

                            var o = data[i].DateWin + '';
                            var match = o.match(/(\d{4})(\d{2})(\d{2})/);
                            var betterDateStr = match[2] + '/' + match[3] + '/' + match[1];

                            var l1 = new Array();
                            l1.push(betterDateStr);
                            l1.push(data[i].CountBet);
                            l1.push(data[i].CountAcc);
                            r1.push(l1);

                            var l2 = new Array();
                            l2.push(betterDateStr);
                            l2.push(data[i].SUMBetMoney / 1000);
                            l2.push(data[i].SUMProfit / 1000);
                            r1sum.push(l2);


                        }

                        google.setOnLoadCallback(drawChart1);
                        google.setOnLoadCallback(drawChart2);

                        function drawChart1() {
                            var data = google.visualization.arrayToDataTable(r1);
                            var options = {
                                title: 'BIÊU ĐỒ SỐ GIAO DỊCH - NGƯỜI CHƠI',
                                curveType: 'function',
                                legend: { position: 'bottom' },
                                series: { 0: { color: 'blue', areaOpacity: 0.3, lineWidth: 2 } },
                                series: { 1: { color: 'red', areaOpacity: 0.3, lineWidth: 2 } }

                            };
                            var chart = new google.visualization.LineChart(document.getElementById('chart_loinhuan'));
                            chart.draw(data, options);

                        }

                        function drawChart2() {
                            var data = google.visualization.arrayToDataTable(r1sum);
                            var options = {
                                title: 'BIÊU ĐỒ TIỀN THEO NGÀY - ĐV: (VCoin)',
                                curveType: 'function',
                                legend: { position: 'bottom' },
                                series: { 0: { color: 'blue', areaOpacity: 0.3, lineWidth: 2 } },
                                series: { 1: { color: 'red', areaOpacity: 0.3, lineWidth: 2 } }

                            };
                            var chart = new google.visualization.LineChart(document.getElementById('chart_giaodich'));
                            chart.draw(data, options);

                            var hideTT = document.getElementById("hideTT");
                            var b = false;
                            hideTT.onclick = function () {
                                b = !b;
                                view = new google.visualization.DataView(data);
                                if (b)
                                    view.hideColumns([1]);
                                else
                                    chart.draw(view, options);

                                chart.draw(view, options);
                            }

                        }

                    }
                    $.ajax({
                        type: "GET",
                        url: "/API/Handler1.ashx?p=doanthu",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        cache: false,
                        success: function (data) {
                            format(data);

                        }
                    });
                </script>




            </div>
        </div>
        <div class="clear"></div>

    </telerik:RadAjaxPanel>

</asp:Content>
